<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<style>
			[v-cloak] {
				display: none;
			}
			
			html,
			body {
				height: 100%;
			}
			
			.mui-bar-nav {
				background: #f16456;
				height: 58px;
			}
			
			.mui-bar .mui-title {
				margin-top: 18px;
			}
			
			.mui-bar-nav~.mui-content {
				padding-top: 58px;
			}
			
			.mui-action-back,
			.mui-title,
			.mui-action-back:active,
			.mui-btn-link {
				color: #FFFFFF;
				margin-top: 17px;
			}
			
			.mui-input-row {
				background: white;
				margin-top: 15px;
				margin-left: 20px;
				margin-right: 20px;
				height: 50px;
			}
			
			.mui-input-row span {
				position: absolute;
				left: 16px;
				top: 16px;
				font-size: 14px;
			}
			
			.mui-input-row input {
				height: 100%;
				padding-left: 80px;
			}
			
			.mui-btn {
				border: 1px solid #f16456;
				width: 300px;
				background-color: #f16456;
				height: 45px;
				font-size: 18px;
			}
			
			.mui-btn:active {
				border: 1px solid #de7c79!important;
				background-color: #de7c79!important;
			}
			
			input[type=button] {
				color: #FFFFFF;
				background-color: #f16456;
				height: 100%;
			}
			
			h6 {
				margin-left: 20px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<a class="mui-btn-link mui-pull-right" style="padding-top:2px;color: #ebcd9a;" onclick="vm.topup()" id="balance">111</a>
			<h1 class="mui-title" id="title">发红包</h1>
		</header>
		<div class="mui-content" id="bizVue">
			<div>
				<div class="mui-input-row">
					<span>金币</span>
					<input type="number" @change="function(){vm.amount = Math.floor(vm.amount)}" :placeholder="(room.isVip == 1 ? (room.vipMinAmount + '-' + room.vipMaxAmount) : (center.minAmount + '-' + center.maxAmount)) + '之间'" v-model="amount">
				</div>
				<h6>每人抽到的金币为随机</h6>
				<div class="mui-input-row">
					<span>雷点</span>
					<input type="number" @change="function(){vm.landmine = Math.floor(vm.landmine)}" placeholder="1-9之间" v-model="landmine">
				</div>
				<div class="mui-input-row">
					<span style="color: gray;">红包数</span>
					<input type="text" style="color: #8f8f94;" disabled="disabled" :value="(room.isVip == 1 ? room.vipPacketQty : center.packetQty) + '个'">
				</div>
				<div class="mui-input-row">
					<span style="color: gray;">留言</span>
					<input type="text" style="color: #8f8f94;" value="恭喜发财,大吉大利" disabled="disabled">
				</div>
				<h1 align="center" style="margin-top: 15px;">￥{{amount == null? "0.00" : amount}}</h2>
				<div class="mui-button-row" style="margin-bottom: 20px;margin-top: 10px;">
					<button type="button" class="mui-btn mui-btn-primary" @click="send">塞钱进红包</button>&nbsp;&nbsp;
				</div>
			</div>
		</div>

		<script type="text/javascript" src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/vue.min.js"></script>
		<script type="text/javascript" src="../js/public.js"></script>
		<script type="text/javascript" src="../js/validator.min.js" ></script>
		<script type="text/javascript">
			var vm = new Vue({
				el: '#bizVue',
				data: {
					member: {},
					center: {},
					room: {},
					amount: null,
					landmine: null
				},
				mounted: function() {
					mui.plusReady(function() {
						swipeBack();
						vm.room = plus.webview.currentWebview().room;
						vm.center = plus.webview.currentWebview().center;
						vm.member = JSON.parse(plus.storage.getItem("member"));
						document.getElementById("balance").innerText = "￥" + vm.member.balance;
					});
				},
				methods: {
					topup: function() {
						mui.openWindow({
							id: "deposit",
							url: "../my/deposit.html",
							waiting: {
								autoShow: false
							}
						});
					},
					send: function() {
						if(!vm.amount) {
							mymui("请输入金币");
							return;
						}
						if(vm.room.isVip == 1) {
							if(vm.amount < vm.room.vipMinAmount || vm.amount > vm.room.vipMaxAmount) {
								mymui("金币必须在" + vm.room.vipMinAmount + "-" + vm.room.vipMaxAmount + "之间");
								return;
							}
						} else {
							if(vm.amount < vm.center.minAmount || vm.amount > vm.center.maxAmount) {
								mymui("金币必须在" + vm.center.minAmount + "-" + vm.center.maxAmount + "之间");
								return;
							}
						}
						
						if(!vm.landmine) {
							mymui("请输入雷点");
							return;
						}
						if(vm.landmine < 1 || vm.landmine > 9) {
							mymui("雷点必须在1-9之间");
							return;
						}
						mui("button")[0].disabled = true;
						mui.postJSON(PacketSend,{roomId: vm.room.id, amount: vm.amount, landmine: vm.landmine},function(result) {
							if(result.code == 0) {
								plus.storage.setItem("member", JSON.stringify(result.sender));
								mui.back();
							} else {
								mui("button")[0].disabled = false;
								mymui(result.msg);
							}
						});
					}
				}
			});
		</script>
	</body>

</html>